#include "CNode.h"

CNode::CNode(int nid, double x, double y, double z)
{
    coords[X]=x;
    coords[Y]=y;
    coords[Z]=z;
    id=nid;
    bcset[X]=0;
    bcset[Y]=0;
    bcset[Z]=0;
    bcset[ROTX]=0;
    bcset[ROTY]=0;
    bcset[ROTZ]=0;
    forceset[X]=0;
    forceset[Y]=0;
    forceset[Z]=0;
    forceset[ROTX]=0;
    forceset[ROTY]=0;
    forceset[ROTZ]=0;
    unknown=0;
    restricted[X]=0;
    restricted[Y]=0;
    restricted[Z]=0;
    restricted[ROTX]=0;
    restricted[ROTY]=0;
    restricted[ROTZ]=0;
    solution[X]=0.;
    solution[Y]=0.;
    solution[Z]=0.;
    solution[ROTX]=0.;
    solution[ROTY]=0.;
    solution[ROTZ]=0.;
    unknownSolution[X]=0.;
    unknownSolution[Y]=0.;
    unknownSolution[Z]=0.;
    bilateralUnknown=0;
}

CNode::~CNode()
{
    //dtor
}

double CNode::getDistance(CNode *n)
{
    double x=n->getCoord(X);
    double y=n->getCoord(Y);
    double z=n->getCoord(Z);
    return sqrt((x-coords[X])*(x-coords[X])+(y-coords[Y])*(y-coords[Y])+(z-coords[Z])*(z-coords[Z]));
}

double CNode::getCoord(int dir)
{
    return coords[dir];
}

int CNode::getId()
{
    return id;
}

void CNode::setDisplacement(int dir, double v)
{
    bcset[dir]=1;
    bcvalue[dir]=v;
}

void CNode::setForce(int dir, double v)
{
    forceset[dir]=1;
    bcvalue[dir]=v;
}

bool CNode::checkDisplacement(int n)
{
    return bcset[n];
}

bool CNode::checkForce(int n)
{
    return forceset[n];
}

bool CNode::checkUnknown()
{
    return unknown;
}

double CNode::getBCValue(int n)
{
    return bcvalue[n];
}

double CNode::getUnknownDirection(int n)
{
    return unknownDirection[n];
}

void CNode::setUnknownForce(CNode *n)
{
    unknown=1;
    double x=n->getCoord(X);
    double y=n->getCoord(Y);
    double z=n->getCoord(Z);
    double length=sqrtf((coords[X]-x)*(coords[X]-x)+(coords[Y]-y)*(coords[Y]-y)+(coords[Z]-z)*(coords[Z]-z));
    unknownDirection[X]=(x-coords[X])/length;
    unknownDirection[Y]=(y-coords[Y])/length;
    unknownDirection[Z]=(z-coords[Z])/length;
}

void CNode::setBilateralUnknownForce(CNode *n)
{
    setUnknownForce(n);
    n->setUnknownForce(this);
    bilateralUnknown=1;
    bilateralUnknownNode=n;
}

bool CNode::checkBilateralUnknown()
{
    return bilateralUnknown;
}

CNode* CNode::getBilateralUnknownNode()
{
    return bilateralUnknownNode;
}

void CNode::setRestriction(int dir)
{
    restricted[dir]=1;
}

bool CNode::getRestriction(int dir)
{
    return restricted[dir];
}

void CNode::setSolution(int dir, double v)
{
    solution[dir]=v;
}

double CNode::getSolution(int dir)
{
    return solution[dir];
}

void CNode::setUnknownSolution(int dir, double v)
{
    unknownSolution[dir]=v;
}

double CNode::getUnknownSolution(int dir)
{
    return unknownSolution[dir];
}
